<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>教育主管单位</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/oauthplatform/static/css/x-admin/font.css">
    <link rel="stylesheet" href="/oauthplatform/static/css/x-admin/xadmin.css">
    <link rel="stylesheet" href="/oauthplatform/static/lib/zTree/css/zTreeStyle/zTreeStyle.css">
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a><cite>教育主管单位</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>

<div class="layui-fluid layui-row layui-col-space15">
    <div class="layui-col-sm12 layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-header">详细信息</div>
            <div class="layui-card-body ">
                <form class="layui-form layui-col-space5" id="searchForm">
                    <div class="layui-inline layui-show-xs-block">
                        <select name="isValid" id="isValid">
                            <option value="">是否启用</option>
                            <option value="1">已启用</option>
                            <option value="0">未启用</option>
                        </select>
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="name" id="name" placeholder="请输入角色名称" class="layui-input">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <button class="layui-btn" type="button" onclick="reloadTable()"  title="搜索">
                            <i class="layui-icon">&#xe615;</i>
                        </button>
                        <button type="button" class="layui-btn layui-btn-sm" title="添加" onclick="addRole()">
                            <i class="layui-icon">&#xe654;</i>
                        </button>
                    </div>
                </form>
            </div>

            <div class="layui-card-body">
                <div id="dataTables"></div>
            </div>
        </div>
    </div>

</div>
</body>
<script type="text/javascript" src="/oauthplatform/static/lib/jquery/jquery.3.4.1.js"></script>
<script src="/oauthplatform/static/lib/layui/layui.js" charset="utf-8"></script>
<script src="/oauthplatform/static/lib/other/html5.min.js"></script>
<script src="/oauthplatform/static/lib/other/respond.min.js"></script>
<script src="/oauthplatform/static/lib/zTree/js/jquery.ztree.core.js"></script>
<script src="/oauthplatform/static/lib/x-admin/xadmin.js"></script>
<script type="application/javascript">


    var table ;
    layui.use('table', function(){
        table = layui.table;
        //第一个实例
        table.render({
            elem: '#dataTables'
            ,url: '/oauthplatform/eduManage/list' //数据接口
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": "", //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.records //解析数据列表
                };
            }
            ,page:{ //支持传入 laypage 组件的所有参数（某些参数除外,如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next'] //自定义分页布局
                ,first: false //不显示首页
                ,last: false //不显示尾页
            }
            ,cols: [[ //表头
                {field: 'departmentId', title: '序号'}
                ,{field: 'name', title: '单位名称'}
                ,{
                    field: 'type', title: '单位类型', templet: function (d) {
                        switch (d.type) {
                            case '1':
                                return '省级'
                            case '2':
                                return '市级'
                            case '3':
                                return '区县级'
                            case '4':
                                return '省直管县'
                        }
                    }
                }
                ,{field: 'precinct', title: '管辖区域'}
                ,{field: 'area', title: '所在地区'}
                ,{field: 'departmentParentId', title: '主管部门id',hide:true}
                ,{field: 'departmentParenName', title: '主管部门'}
                ,{field: 'isValid', title: '操作',templet: function(d){
                        var buttonHtml = '';
                        buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="查看" onclick="authorization('+d.id+')"><i class="layui-icon">&#xe672;</i></button>';
                        buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="编辑" onclick="editRole('+d.id+')"><i class="layui-icon">&#xe642;</i></button>';
                        buttonHtml += '<button type="button" class="layui-btn layui-btn-sm" title="删除" onclick="deleteRole('+d.id+')"><i class="layui-icon">&#xe640;</i></button>';
                        return buttonHtml; }}
            ]]
        });
    });

    function reloadTable(){
        table.reload('dataTables',{
            where:{name : $("#name").val(), isValid : $("#isValid").val()}
        });
    }

    function addRole(){ xadmin.open('添加角色', '/oauthplatform/role/add', 600, 700, false); }

    function editRole(id){
        if(id==null||id==''){ layer.msg("参数异常,请联系管理员"); return false; }
        xadmin.open('修改角色','/oauthplatform/role/edit?id='+id, 600, 500,false);
    }

    function authorization(id){
        if(id==null||id==''){ layer.msg("参数异常,请联系管理员"); return false; }
        xadmin.open('授权','/oauthplatform/authorization/index?rid='+id,600, 500,false);
    }

    function deleteRole(id){
        if(id==null||id==''){ layer.msg("参数异常,请联系管理员"); return false; }

        layer.confirm('是否确认删除?', {
            btn: ['确认'] //可以无限个按钮
        }, function(index, layero){
            $.ajax({
                type: "POST",//方法类型
                url: "/oauthplatform/role/delete" ,//url
                data: {id:id},
                success: function (result) {
                    layer.msg(result.msg);
                    if(parseInt(result.code) == 200){
                        setTimeout(function(){ location.reload(); }, 900);
                    }
                },
                error: function (result) { layer.msg("系统异常,请联系管理员"); }
            });
        });
    }
</script>
</html>
